Python console

您所在的位置:网站首页 ipython documentation Python console

Python console

2022-12-07 19:53| 来源: 网络整理| 查看: 265

Working with Python console

The console appears as a tool window every time you choose the corresponding command on the Tools menu. You can assign a shortcut to open Python console: press Ctrl+Alt+S, navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console.

The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

Code completion in the Python console

You can use up and down arrow keys to browse through the history of executed commands, and repeat the desired ones. To preview the variable values calculated in the course of the execution, click Show variables and check the Special Variables list.

Show variables in the Python console

The console is available for all types of Python interpreters and virtual environments, both local and remote.

Preview a variable as an array

When your variables are numpy arrays or dataframes, you can preview them as an array in a separate window. To try it, do one of the following:

Click the link View as Array/View as DataFrame:

Viewing variables in array when running from Python console

From the context menu of a variable, choose View as Array/View as DataFrame:

Viewing variables in data frames when running from Python console

The variable will be opened in the Data tab of the SciView window.

View an array or dataframe in a separate window Run source code from the editor in console

Open file in the editor, and select a fragment of code to be executed.

From the context menu of the selection, choose Execute Selection in Python Console, or pressAlt+Shift+E:

Context menu for executing the code selection

With no selection, the command changes to Execute line in console. Choose this command from the context menu, or press Alt+Shift+E. The line at caret loads into the Python console, and runs.

Watch the code selection execution: Execution of the code selection in the console

By default, the Python console executes Python commands using the Python interpreter defined for the project. However, you can assign an alternative Python interpreter.

Run asyncio coroutines

In the editor, select a fragment of code which contains the definition of an asyncio coroutine.

From the context menu, select Execute Selection in Python Console, or pressAlt+Shift+E:

Selecting and executing asyncio coroutines in the Python console

After the code is executed on the Python console, run the coroutine by using the await keyword:

Execution of the asyncio coroutine in the console Configure Python console settings

In the Settings/Preferences dialog (Ctrl+Alt+S), select Build, Execution, Deployment | Console | Python Console.

Select any available interpreter from the Python interpreter list. Note that you cannot introduce a new interpreter here. If you want to come up with the new interpreter, you need to create it first.

Search an alternative Python interpreter

In needed, click the Configure Interpreters link to inspect the list of the installed packages and add new ones.

Mind the code in the Starting script area. It contains the script that will be executed after you open the Python console. Use it to pre-code some required Python commands.

When working on several Python scripts, you might want to execute each in a separate Python console.

Run several Python consoles

Click New Console to add a new Python console.

By default, each console has the name Python Console with an index. To make a console reflect the script you're running, right-click the console tab, select Rename Console, and enter any meaningful name.

Rename the Python console

All the commands you're running in the Python console, are executed one by one. If the commands require substantial time to get executed, you might want to preview and manage the execution queue.

Manage the command execution queue

Click Command queue on the console toolbar to open the queue.

Console command queue

In the Python Console Command Queue dialog, review the list of commands. If needed, click remove to delete the command from the queue.

Note, once the command is executed, it disappears from the queue. To preview all previously executed commands browse the console history (console history).



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3